package agend.client.gui;

import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;
import javax.swing.UIManager;

import agend.client.gui.utils.AgentInterface;
import agend.client.gui.utils.HandlerView;

public class ClientGui extends JFrame implements WindowListener
{

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	
	private static final long serialVersionUID = 1L;
	
	public ClientGui() throws HeadlessException
	{
		super();

		addWindowListener(this);

		setSize(1000, 700);
		setResizable(false);

		final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
		final java.awt.Point center = ge.getCenterPoint();
		final java.awt.Rectangle bounds = ge.getMaximumWindowBounds();
		final int w = Math.max(bounds.width / 2, Math.min(getWidth(), bounds.width));
		final int h = Math.max(bounds.height / 2, Math.min(getHeight(), bounds.height));
		final int x = center.x - w / 2, y = center.y - h / 2;
		setBounds(x, y, w, h);
		if (w == bounds.width && h == bounds.height)
		{
			setExtendedState(MAXIMIZED_BOTH);
		}
		validate();
		
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	}

	@Override
	public void windowActivated(final WindowEvent e){}

	@Override
	public void windowClosed(final WindowEvent e){}

	@Override
	public void windowClosing(final WindowEvent e)
	{
		AgentInterface agentInterface = (AgentInterface) HandlerView.getAgent();
		agentInterface.shutDown();
	}

	@Override
	public void windowDeactivated(final WindowEvent e){}

	@Override
	public void windowDeiconified(final WindowEvent e){}

	@Override
	public void windowIconified(final WindowEvent e){}

	@Override
	public void windowOpened(final WindowEvent e){}
}
